from django.contrib.auth.models import User
from django.db import models
from db.base_model import BaseModel

# Create your models here.

class Photo(BaseModel):
    """照片"""
    TYPE = (
        ('a', '生活'),
        ('b', '风景'),
        ('c', '美食'),
        ('d', '人物'),
        ('e', '专辑'),
        ('f', '社会'),
    )
    title = models.CharField('标题', max_length=200, default='None')
    intro = models.CharField('简介', max_length=100, blank=True)
    pub_time = models.DateTimeField(
        '发布时间',
        blank=False, null=False, auto_now_add=True)
    photo = models.ImageField(default= 'group1/M00/00/00/rBAABl9qAwaACB5rAAAi_rY1Qyk100.jpg',upload_to='Article_avatar', verbose_name='照片')
    type = models.CharField('分类', max_length=1, choices=TYPE, default='a')
    views = models.PositiveIntegerField('浏览量', default=0)
    like = models.PositiveIntegerField('点赞数', default=0)
    author = models.ForeignKey(
        User,
        verbose_name='作者',
        blank=False,
        null=False,
        on_delete=models.CASCADE)
    article_order = models.IntegerField(
        '排序,数字越大越靠前', blank=False, null=False, default=0)

    def __str__(self):
        return self.title


    class Meta:
        db_table = "louis_gallery"
        verbose_name = "照片库"
        verbose_name_plural = verbose_name
        get_latest_by = 'id'